package com.zx.ishopping.mapper;


import com.github.pagehelper.Page;
import com.zx.ishopping.DTO.CategoryPageQueryDTO;
import com.zx.ishopping.annotation.AutoFill;
import com.zx.ishopping.entity.Category;
import com.zx.ishopping.enums.OperationEnum;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;


import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 获取所有分类
     * @return
     */
    @Select("select * from categories")
    List<Category> getCategoryList();
    

    /**
     * 插入分类
     */
    @AutoFill(value = OperationEnum.INSERT )
    @Insert("insert into categories ( name, description, create_time, update_time, create_user) values" +
            " (#{name},#{description},#{createTime},#{updateTime},#{createUser})")
    void insertCategory(Category categoryO);

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 删除 分类
     * @param ids
     */
    void deleteCategory(List<Long> ids);

    /**
     * 修改分类
     * @param category
     */
    @AutoFill(value = OperationEnum.UPDATE)
    void updateCategory(Category category);

    /**
     * 根据名称查询分类
     * @param name
     * @return
     */
    @Select("select * from categories where name = #{name}")
    Category getCategoryByName(String name);

    /**
     * 根据id查询分类
     * @param id
     * @return
     */
    @Select("select * from categories where id = #{id}")
    Category getCategoryById(Long id);
}
